package com.example.base.tools

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.lang.reflect.Type

object JsonTool {
    private val gson: Gson by lazy {
        GsonBuilder().create()
    }

    fun <T : Any?> json2Object(input: String?, clazz: Class<T>?): T = gson.fromJson<T>(input, clazz)

    fun object2Json(instance: Any?): String = gson.toJson(instance)

    fun <T : Any?> parseObject(input: String?, clazz: Type?): T = gson.fromJson<T>(input, clazz)
}